home *** CD-ROM | disk | FTP | other *** search
/ Aminet 25 / Aminet 25 (1998)(GTI - Schatztruhe)[!][Jun 1998].iso / Aminet / util / time / backclock.lha / BackClock / sources / tracewin.c < prev    next >
C/C++ Source or Header  |  1998-04-11  |  6KB  |  182 lines

  1. /*****************************************************************************
  2.  *
  3.  * Nom:                         tracewin.c
  4.  * Desc:                        fonctions de traçage dans les fenetres
  5.  *
  6.  *
  7.  * version                      : $VER: tracewin.c 2.2 (11.04.98)
  8.  *****************************************************************************
  9.  */ 
  10. #include <exec/memory.h>
  11. #include <graphics/rastport.h>
  12. #include <proto/graphics.h>
  13. #include <proto/exec.h>
  14. #include <math.h>
  15. #include "utils.h"
  16. #include "tracewin.h"
  17.  
  18.  
  19.  
  20.  
  21. struct pt ptSec,
  22.           ptMin,
  23.           ptHeu ;
  24. ULONG mX, mY ;
  25.  
  26. void initwin(idWin * prj) {
  27.   int i ;
  28.   
  29.   mX = prj->backWin.width / 2 ;
  30.   mY = prj->backWin.height / 2 ;
  31.   if (prj->RP1) {
  32.     
  33.     SetAPen(prj->RP1, prj->backWin.cmap[COL_TIC].reg) ;                                                       // couleur jaune
  34.     for(i = 0; i < 360; i=i+30) {
  35.       /* trace les repères des heures
  36.       */
  37.       Move(prj->RP1, ULONG(cos(PI*i/180.0) * (mX-mX/10L)) + mX, ULONG(sin(PI*i/180.0) * (mY-mY/10L)) + mY) ;
  38.       Draw(prj->RP1, ULONG(cos(PI*i/180.0) * mX) + mX, ULONG(sin(PI*i/180.0) * mY) + mY) ;
  39.     }
  40.   }
  41.   /* initalisation des points des aiguilles
  42.    */
  43.   /* secondes
  44.    */
  45.   ptSec.points = 2 ;
  46.   ptSec.fill   = FALSE ;
  47.   ptSec.pt_AI  = NULL ; // needed when freeing
  48.   ptSec.pt_buffer = NULL ; // idem
  49.   ptSec.A[0]   = 0 ;
  50.   ptSec.A[1]   = 180 ;
  51.   ptSec.M[0]   = 5.0 ;
  52.   ptSec.M[1]   = 1.2 ;
  53.   ptSec.angle  = ANGLE_S ;
  54.   /* heures
  55.    */
  56.   ptHeu.points = 5 ;
  57.   ptHeu.fill   = FALSE ;
  58.   ptHeu.pt_AI  = AllocVec(sizeof(struct AreaInfo), MEMF_PUBLIC|MEMF_CLEAR) ;
  59.   ptHeu.pt_buffer = AllocVec(10 * ptHeu.points, MEMF_PUBLIC) ;
  60.   ptHeu.A[0]   = 0 ;
  61.   ptHeu.A[1]   = 100 ;
  62.   ptHeu.A[2]   = 180 ;
  63.   ptHeu.A[3]   = -100 ;
  64.   ptHeu.A[4]   = 0 ;
  65.   ptHeu.M[0]   = 3.0 ;
  66.   ptHeu.M[1]   = 1.1 ;
  67.   ptHeu.M[2]   = 1.2 ;
  68.   ptHeu.M[3]   = 1.1 ;
  69.   ptHeu.M[4]   = 3.0 ;
  70.   ptHeu.angle  = ANGLE_H ;
  71.   
  72.   /* minutes
  73.    */
  74.   ptMin.points =   5 ;
  75.   ptMin.fill   = FALSE ;
  76.   ptMin.pt_AI  = AllocVec(sizeof(struct AreaInfo), MEMF_PUBLIC|MEMF_CLEAR) ;
  77.   ptMin.pt_buffer = AllocVec(10 * ptMin.points, MEMF_PUBLIC) ;
  78.   ptMin.A[0]   =   0 ;
  79.   ptMin.A[1]   =  150 ;
  80.   ptMin.A[2]   = 180 ;
  81.   ptMin.A[3]   = -150 ;
  82.   ptMin.A[4]   =   0 ;
  83.   ptMin.M[0]   =   4 ;
  84.   ptMin.M[1]   =   1.3 ;
  85.   ptMin.M[2]   =   1.2 ;
  86.   ptMin.M[3]   =   1.3 ;
  87.   ptMin.M[4]   =   4 ;
  88.   ptMin.angle  = ANGLE_M ;
  89.   effacer(prj) ;
  90.   retracer(prj) ;
  91.  
  92. }
  93. void free_twin(idWin * prj) {
  94.   if (ptSec.pt_AI)     FreeVec(ptSec.pt_AI) ;
  95.   if (ptSec.pt_buffer) FreeVec(ptSec.pt_buffer) ;
  96.   
  97.   if (ptMin.pt_AI)     FreeVec(ptMin.pt_AI) ;
  98.   if (ptMin.pt_buffer) FreeVec(ptMin.pt_buffer) ;
  99.  
  100.   if (ptHeu.pt_AI)     FreeVec(ptHeu.pt_AI) ;
  101.   if (ptHeu.pt_buffer) FreeVec(ptHeu.pt_buffer) ;
  102.  
  103.  
  104. }
  105.  
  106. void reinit_win(idWin * prj) {
  107.   free_twin(prj) ;
  108.   initwin(prj) ;
  109. }
  110.  
  111. void effacer(idWin * prj) {
  112. //  BltBitMapRastPort(prj->wb->RastPort.BitMap, prj->backWin.posX, prj->backWin.posY, prj->RP1, 0, 0, prj->backWin.width, prj->backWin.height, 0xc0) ;
  113.   WaitBlit() ;
  114.   BltBitMapRastPort(prj->RP1->BitMap, 0,0, prj->RP2, 0, 0, prj->backWin.width, prj->backWin.height, 0xc0) ;
  115. }
  116. void retracer(idWin * prj) {
  117.   SetAPen(prj->RP2, prj->backWin.cmap[COL_SEC].reg) ;
  118.   tracerAiguilles(prj, &ptSec, prj->sec, NULL) ;
  119.   SetAPen(prj->RP2, prj->backWin.cmap[COL_MIN].reg) ;
  120.   tracerAiguilles(prj, &ptMin, prj->min, NULL) ;
  121.   SetAPen(prj->RP2, prj->backWin.cmap[COL_HEU].reg) ;
  122.   tracerAiguilles(prj, &ptHeu, prj->heu, prj->min/2) ;
  123.   WaitBlit() ;
  124.   BltBitMapRastPort(prj->RP2->BitMap, 0,0, prj->win->RPort, 0, 0, prj->backWin.width, prj->backWin.height, 0xc0) ;
  125. }
  126. void tracerAiguilles(idWin * prj, struct pt * ptAigu, UBYTE p_time, UBYTE an_inc) {
  127.   int i ;
  128.   if (ptAigu->pt_AI) {
  129.     // reinitialise AreaInfo
  130.     ptAigu->pt_AI->Count = NULL ; // reset vertices
  131. //    prj->win->RPort->AreaInfo = ptAigu->pt_AI ; // set the areainfo
  132.   }
  133.   
  134.   Move(prj->RP2, mX+(ULONG)(cos(PI*(ptAigu->A[0]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mX-mX/ptAigu->M[0])), 
  135.                         mY+(ULONG)(sin(PI*(ptAigu->A[0]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mY-mY/ptAigu->M[0]))) ;
  136.  
  137.   if (!ptAigu->fill) {
  138.     // tracer sans remplissage
  139.     // no fill
  140.     for(i = 0; i<ptAigu->points; i++)
  141.       Draw(prj->RP2, mX+(ULONG)(cos(PI*(ptAigu->A[i]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mX-mX/ptAigu->M[i])), 
  142.                             mY+(ULONG)(sin(PI*(ptAigu->A[i]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mY-mY/ptAigu->M[i]))) ;
  143.   }else {
  144. /*    // avec remplissage
  145.     // fill
  146.     
  147.     InitArea(ptAigu->pt_AI, ptAigu->pt_buffer, ptAigu->points) ;
  148.     AreaMove(prj->win->RPort, mX+(ULONG)(cos(PI*(ptAigu->A[0]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mX-mX/ptAigu->M[0])), 
  149.                               mY+(ULONG)(sin(PI*(ptAigu->A[0]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mY-mY/ptAigu->M[0]))) ;
  150.  
  151.     for(i = 0; i < ptAigu->points; i++)
  152.       AreaDraw(prj->win->RPort, mX+(ULONG)(cos(PI*(ptAigu->A[i]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mX-mX/ptAigu->M[i])), 
  153.                                 mY+(ULONG)(sin(PI*(ptAigu->A[i]+p_time*ptAigu->angle+an_inc-90.0)/180.0)*(mY-mY/ptAigu->M[i]))) ;
  154.     
  155.     AreaEnd(prj->win->RPort) ;*/
  156.   }
  157. }
  158.  
  159. void init_bitmap(idWin * prj) {
  160.   /* initialize tmp rastport and bitmap
  161.    */
  162.   prj->RP1 = AllocVec(sizeof(struct RastPort), MEMF_PUBLIC) ;
  163.   prj->RP2 = AllocVec(sizeof(struct RastPort), MEMF_PUBLIC) ; 
  164.   InitRastPort(prj->RP1) ;
  165.   InitRastPort(prj->RP2) ;
  166.   prj->RP1->BitMap = AllocBitMap(prj->backWin.width, prj->backWin.height, prj->wb->RastPort.BitMap->Depth, BMF_CLEAR|BMF_DISPLAYABLE, NULL) ;
  167.   prj->RP2->BitMap = AllocBitMap(prj->backWin.width, prj->backWin.height, prj->wb->RastPort.BitMap->Depth, BMF_CLEAR|BMF_DISPLAYABLE, NULL) ;
  168.   WaitBlit() ;
  169.   BltBitMapRastPort(prj->wb->RastPort.BitMap, prj->backWin.posX, prj->backWin.posY, prj->RP1, 0, 0, prj->backWin.width, prj->backWin.height, 0xc0) ;
  170. }
  171.  
  172. void free_bitmap(idWin * prj) {
  173.  
  174.   
  175.   if (prj->RP1 && prj->RP1->BitMap) FreeBitMap(prj->RP1->BitMap) ;
  176.   if (prj->RP2 && prj->RP2->BitMap) FreeBitMap(prj->RP2->BitMap) ;
  177.   if (prj->RP1) FreeVec(prj->RP1) ;
  178.   if (prj->RP2) FreeVec(prj->RP2) ;
  179.   prj->RP1 = prj->RP2 = NULL ;
  180. }
  181.  
  182.